package servicedevmap

import (
	"emsctrl/public"
)

var (
	PV_YGGL = "pvgl"
)

type PvdevMap struct {
	yggl float32
}

var PvMap map[string]map[string]string

func init() {
	PvMap = make(map[string]map[string]string)
}

func (p *PvdevMap) Analysis_string(info []string) {
	var ytype string
	var key string
	var mapv string
	for i, s := range info {
		switch i {
		case 0:
			break
		case 1:
			ytype = s
		case 2:
			key = s
		case 3:
			mapv = s
		}
	}
	if _, ok := pcsMap[ytype]; ok {

	} else {
		pcsMap[ytype] = make(map[string]string)
	}
	pcsMap[ytype][key] = mapv
}

func (p *PvdevMap) upGradeDevData(index int, devtype, devname, paratype string, datum public.DataVal) {
	reg := StationMap[index][devtype][devname]

	if _, ok := pcsMap[paratype]; ok {
		switch pcsMap[paratype][datum.Key] {
		case PV_YGGL:
			if reg.RegMap == nil {
				reg.RegMap = make(map[string]RegInfo)
			} else {

			}
			if _, ok1 := reg.RegMap[pcsMap[paratype][datum.Key]]; ok1 {
				info := reg.RegMap[pcsMap[paratype][datum.Key]]
				info.Val = datum.Val
				info.Addr = datum.RegAddr
				info.PType = paratype
				reg.RegMap[pcsMap[paratype][datum.Key]] = info
			} else {
				reg.RegMap[pcsMap[paratype][datum.Key]] = RegInfo{Key: datum.Key, Val: datum.Val, Addr: datum.RegAddr, PType: paratype}
			}

		default:

		}
	}
	StationMap[index][devtype][devname] = reg
}

func (p *PvdevMap) upGradeCurrPolicyPara(devtype, devName, paratype string) {
	*p = PvdevMap{}
	for _, m := range StationMap {
		if _, ok := m[devtype][devName]; ok {
			reg := m[devtype][devName]
			for s, info := range reg.RegMap {
				switch s {
				case PCS_YGGL:
					p.yggl += info.Val
				}
			}
		}
	}
	G_curr_policy.RemoteMetering.PvActivePower = p.yggl
}
